#ifndef __common_h__
#define __common_h__

#include <string>
#include <windows.h>
#include <tchar.h>
#include <atlstr.h>

namespace common
{
    class WinString
    {
    public:
        static CString UTF8ToUnicode( LPCSTR pszText );
        static CStringA UnicodeToUTF8( LPCWSTR pszwText );
    };

    class WindowDC
    {
    public:
        enum Type
        {
            DefaultDC       = 0x00000001,
            HandlerDC       = 0x00000002
        };

        WindowDC();
        WindowDC( HWND hWnd );

        ~WindowDC();

        operator HDC(){ return m_hDC; }

    private:
        DWORD   m_dwType;
        HWND    m_hWnd;
        HDC     m_hDC;
    };

    class WinMemoryDC
    {
    public:
        enum Type
        {
            DefaultDC       = 0x00000001,
            CompatibleDC    = 0x00000002,
            BitmapDC        = 0x00000004
        };

        WinMemoryDC();
        WinMemoryDC( HDC hDC );
        WinMemoryDC( HBITMAP hBitmap );

        ~WinMemoryDC();

        operator HDC(){ return m_hMemDC; }

    private:
        DWORD   m_dwType;
        HDC     m_hMemDC;
        HDC     m_hDC;
        HBITMAP m_hBitmap;
    };

    class WinHelper
    {
    public:
        static BOOL CenterWindow( HWND hWnd, HWND hWndParent );
    };

    class WinEvent
    {
    public:
        WinEvent();
        ~WinEvent();

        void Set();
        void Reset();
        BOOL Wait( DWORD dwTimeout = INFINITE );

        operator HANDLE(){ return m_hEvent; }

    private:
        HANDLE m_hEvent;
    };
}

#endif